package com.huikeportal.service.impl;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.huikeportal.dao.ArticleServiceMapper;
import com.huikeportal.model.Article;
import com.huikeportal.service.ArticleService;

@Service("articleService")
public class ArticleServiceImpl implements ArticleService {

	@Autowired
	private ArticleServiceMapper articleMapper;
	public List<Article> getArticleList(Article article) throws Exception {
		// TODO Auto-generated method stub
		return articleMapper.getArticleList(article);
	}
	public List<Article> getArticleListMobile(Article article) throws Exception {
		// TODO Auto-generated method stub
		return articleMapper.getArticleListMobile(article);
	}
	public Article getFirstArticle(Article article) throws Exception {
		// TODO Auto-generated method stub
		return articleMapper.getFirstArticle(article);
	}
	public Article getArticle(Article article) throws Exception{
		return articleMapper.getArticle(article);
	}
	public Article getPreArticle(Article article) throws Exception{
		return articleMapper.getPreArticle(article);
	}
	public Article getNextArticle(Article article) throws Exception{
		return articleMapper.getNextArticle(article);
	}
	public String getTimeAgo(String datetime) throws Exception{
		Calendar c1 = Calendar.getInstance();
        c1.setTime(new Date());
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		java.util.Date now = df.parse(df.format(c1.getTime()));
		java.util.Date date=df.parse(datetime);
		long l=now.getTime()-date.getTime();
		long day=l/(24*60*60*1000);
		long hour=(l/(60*60*1000)-day*24);
		long min=((l/(60*1000))-day*24*60-hour*60);
		//long s=(l/1000-day*24*60*60-hour*60*60-min*60);
		if(day>0){
			return day+"天前";
		}
		if(hour>0){
			return hour+"小时前";
		}
		if(min>0){
			return min+"分钟前";
		}
		return "刚刚";
	}
	public List<Article> getHotArticles(String source) throws Exception{
		return articleMapper.getHotArticles(source);
	}
	public Article getQYAtricle(String source) throws Exception{
		return articleMapper.getQYAtricle(source);
	}
	public List<Article> getAtricles(int category,String source) throws Exception{
		Article art=new Article();
		art.setCategory(category+"");
		art.setSource(source);
		return articleMapper.getAtricles(art);
	}
	public List<Article> getAtricles2(Article art) throws Exception{
		return articleMapper.getAtricles2(art);
	}
	public void clickPlusOne(Article article)throws Exception
	{
		 articleMapper.clickPlusOne(article);
	}
}
